package org.firebug.common.tools.core;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * @Author: 张晓东
 */
public final class DecimalTools {
    public static BigDecimal format(BigDecimal a, int scale, RoundingMode mode) {
        return a.setScale(scale, mode);
    }

    public static BigDecimal add2(BigDecimal a, BigDecimal b) {
        return a.add(b).setScale(2, RoundingMode.HALF_UP);
    }

    public static BigDecimal add(BigDecimal a, BigDecimal b, int scale, RoundingMode mode) {
        return a.add(b).setScale(scale, mode);
    }

    public static BigDecimal sub2(BigDecimal a, BigDecimal b) {
        return a.subtract(b).setScale(2, RoundingMode.HALF_UP);
    }

    public static BigDecimal sub(BigDecimal a, BigDecimal b, int scale, RoundingMode mode) {
        return a.subtract(b).setScale(scale, mode);
    }

    public static BigDecimal mul2(BigDecimal a, BigDecimal b) {
        return a.multiply(b).setScale(2, RoundingMode.HALF_UP);
    }

    public static BigDecimal mul(BigDecimal a, BigDecimal b, int scale, RoundingMode mode) {
        return a.multiply(b).setScale(scale, mode);
    }

    public static BigDecimal div2(BigDecimal a, BigDecimal b) {
        return a.divide(b,2, RoundingMode.HALF_UP);
    }

    public static BigDecimal div(BigDecimal a, BigDecimal b, int scale, RoundingMode mode) {
        return a.divide(b).setScale(scale, mode);
    }

    private DecimalTools() {
    }
}
